﻿using INTEX.DataBase;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Controls;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class YCAFSAV95 
    {
        
        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            string Mandant = txtMANDANT.Text.ToUpper();
            string userID = m_Data.Left(txtUserID.Text.ToUpper() + "        ", 8);
            System.Security.SecureString SPassword = txtPassword.SecurePassword;
            IntPtr p = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(SPassword);
            string Password = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p);
            DataRow dwHR = app.UserValid(userID, Password);
            if (dwHR == null)
            {
                MessageBox.Show("请检查登陆信息");
                return;
            }
          
        }
        public override void OnWorkflowIDChange(string wfid)
        {
            base.OnWorkflowIDChange(wfid);
            try
            {
                dwWFEvent = null;
                DataSet SResult = m_Data.INTEXDBC.QueryICC_WFEVENTS(wfid, 1);
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    dwWFEvent = row;
                }
                if (dwWFEvent == null)
                    return;
                string events = dwWFEvent["WFEVENTS"].ToString().Trim();
                switch (events)
                {
                    case "A001010"://意向单创建
                    case "A001020"://主面料已经审核
                    case "A003001"://外发厂需指定 
                        ART = dwWFEvent["ARTICLE"].ToString();
                        KRS = dwWFEvent["KRS"].ToString();
                        LFD = dwWFEvent["LFD"].ToString();
                        txtNEWDATE.Text = "2";
                        btnQuery_Click(null, null);
                        if (vwABPOS.View != null)
                            vwABPOS.View.MoveCurrentToPosition(0);
                        tabDetail.Focus();
                        break;
                    case "A003010"://原料不足
                    case "A003020"://原料不足
                    case "A003030"://原料不足
                    case "A003040"://原料不足
                    case "A003050"://原料不足
                    case "A003060"://原料不足
                            ART = dwWFEvent["ARTICLE"].ToString();
                        KRS = dwWFEvent["KRS"].ToString();
                        LFD = dwWFEvent["LFD"].ToString();
                        txtNEWDATE.Text = "2";
                        btnQuery_Click(null, null);
                        if (vwABPOS.View != null)
                            vwABPOS.View.MoveCurrentToPosition(0);
                        tabMAT.Focus();
                        break;
                    default:
                        break;
                           
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnMATConfirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dwABAUFM == null)
                {
                    MessageBox.Show("请选择一个原料");
                    return;
                }
                DataRow dwData = null;
                switch (dwABAUFM["MTYPE"].ToString().Trim())
                {
                    case "F":
                        dwData = SetEnv.WDECK.NewRow();
                        dwData["WDMANDANT"] = dwABAUFM["ABAMANDANT"];
                        dwData["WDAUFKRS"] = dwABAUFM["ABAVKAUFKRS"];
                        dwData["WDAUFLFD"] = dwABAUFM["ABAVKAUFLFD"];
                        dwData["WDART"] = dwABAUFM["ABAART"];
                        dwData["WDFARBE"] = dwABAUFM["ABAFARBE"];
                        dwData["WDANZSTK"] = "001";
                        INTEXDBC.UpdateWDECK(dwData, app.company, 4);
                        break;
                    case "T":
                        dwData = SetEnv.FDECK.NewRow();
                        dwData["FDMANDANT"] = dwABAUFM["ABAMANDANT"];
                        dwData["FDAUFKRS"] = dwABAUFM["ABAVKAUFKRS"];
                        dwData["FDAUFLFD"] = dwABAUFM["ABAVKAUFLFD"];
                        dwData["FDART"] = dwABAUFM["ABAART"];
                        dwData["FDFARBE"] = dwABAUFM["ABAFARBE"];
                        dwData["FDGROE"] = dwABAUFM["ABAGROE"];
                        dwData["FDKOMMISS"] = 1;
                        INTEXDBC.UpdateFDECK(dwData, app.company, 3);
                        //
                        break;
                }

                btnWFConfirm_Click(null, null);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
      
     

        private void btnWFConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (dwWFEvent == null)
                return;
            dwWFEvent["CONTROL"] = "OK";
            dwWFEvent["CHGUSER"] = m_Data.UserID;
            dwWFEvent["CHGTIME"] = Helpers.Helper.Left(System.DateTime.Now.ToString(), 20);
            m_Data.INTEXDBC.UpdateICC_WFEVENTS(dwWFEvent); 
        }

        private void btnWFReject_Click(object sender, RoutedEventArgs e)
        {
            if (dwWFEvent == null)
                return;
            dwWFEvent["CONTROL"] = "JJ";
            dwWFEvent["CHGUSER"] = m_Data.UserID;
            dwWFEvent["CHGTIME"] = Helpers.Helper.Left(System.DateTime.Now.ToString(), 20);
            m_Data.INTEXDBC.UpdateICC_WFEVENTS(dwWFEvent);
            
        } 
        
    }
}
